package com.yearner.reviewplan.apijson;

import apijson.NotNull;
import apijson.framework.*;

import java.rmi.ServerException;

public class MyAPIJSONApplication  {
    @NotNull
    public static MyAPIJSONCreator DEFAULT_APIJSON_CREATOR;
    static {
        DEFAULT_APIJSON_CREATOR = new MyAPIJSONCreator();
    }

    /**初始化，加载所有配置并校验
     * @return
     * @throws ServerException
     */
    public static void init() throws ServerException {
        init(true, DEFAULT_APIJSON_CREATOR);
    }
    /**初始化，加载所有配置并校验
     * @param shutdownWhenServerError
     * @return
     * @throws ServerException
     */
    public static void init(boolean shutdownWhenServerError) throws ServerException {
        init(shutdownWhenServerError, DEFAULT_APIJSON_CREATOR);
    }
    /**初始化，加载所有配置并校验
     * @param creator
     * @return
     * @throws ServerException
     */
    public static void init(@NotNull MyAPIJSONCreator creator) throws ServerException {
        init(true, creator);
    }
    /**初始化，加载所有配置并校验
     * @param shutdownWhenServerError
     * @param creator
     * @return
     * @throws ServerException
     */
    public static void init(boolean shutdownWhenServerError, @NotNull MyAPIJSONCreator creator) throws ServerException {
        System.out.println("\n\n\n\n\n<<<<<<<<<<<<<<<<<<<<<<<<< APIJSON 开始启动 >>>>>>>>>>>>>>>>>>>>>>>>\n");
        DEFAULT_APIJSON_CREATOR = creator;

        // 统一用同一个 creator
        APIJSONCreator creator1 = new APIJSONCreator();
        APIJSONSQLConfig.APIJSON_CREATOR = creator1;
        APIJSONParser.APIJSON_CREATOR = creator;
        APIJSONController.APIJSON_CREATOR = creator1;


        System.out.println("\n\n\n开始初始化:权限校验配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
        try {
            APIJSONVerifier.init(shutdownWhenServerError, creator);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("\n完成初始化:权限校验配置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");



        System.out.println("\n\n\n开始初始化:远程函数配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
        try {
//            APIJSONFunctionParser.init(shutdownWhenServerError, creator1);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("\n完成初始化:远程函数配置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

        System.out.println("开始测试:远程函数 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
        try {
//            APIJSONFunctionParser.test();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("\n完成测试:远程函数 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");



        System.out.println("\n\n\n开始初始化:请求校验配置 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
        try {
            StructureUtil.init(shutdownWhenServerError, creator1);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("\n完成初始化:请求校验配置 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

        System.out.println("\n\n\n开始测试:请求校验 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
        try {
            StructureUtil.test();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("\n完成测试:请求校验 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");




        System.out.println("\n\n<<<<<<<<<<<<<<<<<<<<<<<<< APIJSON 启动完成，试试调用自动化 API 吧 ^_^ >>>>>>>>>>>>>>>>>>>>>>>>\n");
    }

}
